﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Xinkui.WebModel.BasicControl;
using Xinkui.WebModel;
using Xinkui.DataAccess.AutoGenerator;
using Xinkui.Common;
using Xinkui.WebModel.Data;

public partial class UserControl_fore_UC_Search_Product : ForeControl {

    protected int _pageSIze = 8;
    public int PageSIze {
        get {
            return _pageSIze;
        }
        set {
            if (_pageSIze == value)
                return;
            _pageSIze = value;
        }
    }

    public string ProductListURL { get; set; }

    public string CompanyListURL { get; set; }

    public SearchQueryData Query { get; set; }

    protected void Page_Load(object sender, EventArgs e) {
        Query = SearchQueryData.Create();

        int total = 0;
        if (!string.IsNullOrEmpty(Query.Keyword)) {
            var listSource = Singleton<ProductInfoDataAccess>.Instance.SearchProducts(Query.PageIndex, PageSIze, Query.Keyword, out total);

            this.rptProductSource.DataSource = listSource;
            this.rptProductSource.DataBind();


            UC_RewritePager1.FormatUrl = true;
            UC_RewritePager1.CoverNav = false;

            this.UC_RewritePager1.NoteTotal = total;
            this.UC_RewritePager1.JumpUrl = URLHelper.LinkToSearchProducts(Query.Keyword) + "&p={0}";//"ProductListForImage.aspx?com=1&p={0}";//JumpUrl;
            this.UC_RewritePager1.PageIndex = Query.PageIndex;
            this.UC_RewritePager1.PageSize = PageSIze;
        }
        else {
            UC_RewritePager1.Visible = false;
            
        }
    }


    public string BindingProductProperty(string title, object o) {
        if (o != null && !string.IsNullOrEmpty(o.ToString())) {
            return string.Format(@" <div class=""para""><strong>{1}:</strong>{0}</div>", o, title);
        }
        return string.Empty;
    }
}